package com.example.dotavideo.util;

import java.io.File;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;

import com.example.dotavideo.R;
import com.example.dotavideo.base.DotaVideoApplication;

public class CommonsUtil {
  
  public static final String ROOT_PATH = "/doatvideo/";
  public static final String PHOTO_PATH = ROOT_PATH + "photo/";
  public static final String CACHE_PATH = ROOT_PATH + "cache/";
  
  public static View createListViewLoadMore(Context context) {
    LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(R.layout.listview_loadmore_view, null);
    return v;
  }
  
  public static Bitmap getBitmapResources(int id) {
    return BitmapFactory.decodeResource(DotaVideoApplication.getInstance().getResources(), id);
  }
  
  public static boolean isCreateDir() {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
      String ROOT = Environment.getExternalStorageDirectory().getPath();
      File path = new File(ROOT + ROOT_PATH);
      if (!path.exists()) {
        path.mkdirs();
      }

      path = new File(ROOT + PHOTO_PATH);
      if (!path.exists()) {
        path.mkdirs();
      }
      path = new File(ROOT + CACHE_PATH);
      if (!path.exists()) {
        path.mkdirs();
      }
      return true;
    } else {
      return false;
    }
  }
  
  
  /**
   * 获取存储路径
   * 
   * @param path ROOT_PATH,PHOTO_PATH,CACHE_PATH,ARTICLE_PATH,LOG_PATH
   * @return
   */
  public static String getStoragePath(String path) {
    if (isCreateDir()) {
      return Environment.getExternalStorageDirectory().getPath() + path;
    } else {
      return "/mnt/sdcard/";
    }
  }
  
  
}
